<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
login
  <div>
    用户名 <input id="username"/>
  </div>
  <div>
    密码：<input type="password" id="password"/>
  </div>
  <div>
    <button id="login">登录-get</button>
    <button id="loginpost">登录-post</button>
  </div>

<script>
  const ologin = document.querySelector("#login")
  const ologinpost = document.querySelector("#loginpost")
  const username = document.querySelector("#username")
  const password = document.querySelector("#password")

  ologin.onclick = () => {
    console.log(username.value, password.value)
    // get 请求
    fetch(`/api/login?username=${username.value}&password=${password.value}`).then(res => res.json()).then(res => {
      console.log(res)
    })
  }
  ologinpost.onclick = () => {
    console.log(username.value, password.value)
    // get 请求
    fetch(`/api/loginpost`,{
      method: "post",
      body: JSON.stringify({
        username: username.value,
        password: password.value
      }),
      headers: {
        "Content-type": "application/json"
      }
    }).then(res => res.text()).then(res => {
      console.log(res)
    })
  }
</script>
</body>
</html>